import React, { Component } from "react";
import { InterfaceG } from "@config/Config";
import yhTools from "@tools/yh";
import { Toast } from "antd-mobile";
//小辉付中间页，由于优化小辉付首页，拆分成三个首页页面（已授信首页，授信中首页，未授信首页），外部自定义跳转不能根据授信状态配置，暂时用中间节解决跳转问题。
class XhfIndex extends Component {
	constructor(props) {
		super(props);
		this.state = {};
	}

	/**
	 * @msg: 查询授信状态
	 * @param {*}
	 * @return {*}
	 */
	credit_queryCreditApplyStatus = () => {
		Toast.loading("加载中...", 100);
		const objs = {
			url: InterfaceG.credit_queryCreditApplyStatus,
			params: { pruductNum: "601" }
		};
		yhTools.request(objs).then(res => {
			let pathName = "";
			if (res.code === "0") {
				if (res.data) {
					const { applyStatus } = res.data;
					//0未授信，1已授信，2授信中，4授信拒绝

					if (applyStatus === "0") {
						pathName = "/xhfHomeNoCredit";
					} else if (applyStatus === "1") {
						pathName = "/xhfHomeCredit";
					} else if (applyStatus === "2") {
						pathName = "/xhfHomeCrediting";
					} else if (applyStatus === "4") {
						pathName = "/xhfHomeNoCredit";
					}
					this.props.history.push(pathName);
				}
			} else {
				Toast.info(res.message, 2);
				return false;
			}
			Toast.hide();
		});
	};

	componentDidMount() {
		this.credit_queryCreditApplyStatus();
	}

	render() {
		return <div>跳转中...</div>;
	}
}

export default XhfIndex;
